<template>
	<view>
		<view class="head lector-top">
			<view class="padding lector-detail">
				<view class="lector-bg" :style="'background-image: url('+data.lecturer.background_Img+');'"></view>
				<view class="cu-bar">
					<view class="action" @click="doback">
						<text class="cuIcon-back text-white"></text> 
					</view>
					<view class="content text-bold"></view>
				</view>
				<view class="cu-list menu-avatar comment user-card">
					<view class="cu-item">
						<view class="cu-avatar round xxl border" :style="'background-image:url('+this.data.lecturer.lecturer_Img+');'"></view>
						<view class="content">
							<view class="text-bold">
								{{data.lecturer.name}}
							</view>
							<view class="text-content text-df">
								{{data.lecturer.intro}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="padding-sm bg-white lector-total">
				<view class="cu-bar tabbar shop">
					<view class="action">
						<view class="text-xl text-black">
							{{data.concern}}
						</view> 订阅
					</view>
					<view class="action">
						<view class="text-xl text-black">
							{{data.count}}
						</view> 课程
					</view>
					<view class="action">
						<view class="text-xl text-black">
							{{data.lector.specials}}
						</view> 专栏
					</view>
					<view class="btn-group nospace">
						<button class="cu-btn round-bottomleft-only shadow-blur" @click="doFavor(data.lecturer.id)" :class="data.lecturer.hasfavor?'':'bg-gradual-yellow'">{{data.lecturer.hasfavor?'已关注':'关注'}}</button>
						<button class="cu-btn round-right-only shadow-blur bg-gradual-orange" open-type="share" v-if="platform=='wxapp'">分享</button>
						<button class="cu-btn round-right-only shadow-blur bg-gradual-orange" v-else @click="showshare=true">分享</button>
					</view>
				</view>
			</view>
		</view>
		<view class="lector-content">
			<view class="lector-tab bg-white">
				<view class="content-nav border-bottom padding-bottom-xs">
					<scroll-view scroll-x class="bg-white nav" scroll-with-animation>
						<view class="cu-item" :class="currentshow=='lesson'?'cur':''" @click="currentshow='lesson'">课程</view>
						<view class="cu-item" :class="currentshow=='special'?'cur':''" @click="currentshow='special'">专栏</view>
						<view class="cu-item" :class="currentshow=='content'?'cur':''" @click="currentshow='content'">讲师介绍</view>
					</scroll-view>
				</view>
				<view class="content-tab">
					<view class="tab-item" :class="currentshow=='lesson'?'active':''">
						<lessons :lessons="data.lessons"></lessons>
					</view>
					<view class="tab-item" :class="currentshow=='special'?'active':''">
						<div class="specials padding">
							<view class="text-empty" v-if="data.specials.length==0">空空如也</view>
							<view class="cu-card article">
								<view class="cu-item" @click="naviTo('special/detail',{id:item.id})" v-for="(item, index) in data.specials" :key="index">
									<view class="content">
										<image class="cover" :src="item.cover" mode="aspectFill"></image>
										<view class="desc">
											<view class="title">{{item.title}}</view>
											<view class="text-content text-warp">{{item.subtitle}}</view>
											<view>
												<scorebar :score="item.score" size="sm"></scorebar>
											</view>
										</view>
									</view>
								</view>
							</view>
						</div>
					</view>
					<view class="tab-item" :class="currentshow=='content'?'active':''">
						<view class="padding lector-bio">
							<view class="bg-orange light text-content margin-bottom-sm padding-sm">{{data.lecturer.intro}}</view>
							<rich-text v-if="data.lector.bio!=''" selectable="true" :nodes="data.lector.bio"></rich-text>
							<view class="text-empty" v-else>
								<text class="text-center">讲师未上传更多资料</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<share :platform="platform" :shareinfo="shareinfo" @closeshare="showshare=false" :showshare="showshare"></share>
	</view>
</template>

<script>
	import {mapState} from 'vuex'
	import core from "@/static/core.js"
	import lessons from "@/components/util/lessons.vue"
	import scorebar from "@/components/util/scorebar.vue"
	import share from "@/components/util/share.vue"
	
	export default {
		components: {lessons, scorebar, share},
		computed: mapState(['hasLogin']),
		data() {
			return {
				uid:0,
				currentshow:'lesson',
				platform:'',
				showshare:false,
				shareinfo:{
					url:'',
					providers:4,
					provider:{}
				},
				data:{
					"title": "",
					"lector": {
						"uid": 0,
						"collection": 0,
						"lid": 0,
						"name": "",
						"proportion": "",
						"cover": "",
						"summary": "",
						"displayorder": 0,
						"nickname": "",
						"realname": "",
						"mobile": 0,
						"gender": 0,
						"qq": "",
						"bio": "",
						"lector": "",
						"lproportion": 0,
						"aid": 0,
						"applytime": 0,
						"state": "",
						"sex": "",
						"lessons": 0,
						"specials": 0,
						"hasfavor": false,
						
					},
					"favor": {
						"id": 0
					},
					"concern":0,
					"lessons": [],
					"url":"",
					"specials": [],
					"lecturer": [],
					"count":{},
					"selcourse":[]
				},
			}
		},
		onLoad(options) {
			if(options.id==options.id){
				this.jiangshi(options.id)
			}else{
				alert("ok")
			}
			// if(typeof(options.uid)=='undefined' || !options.uid) return core.toast('参数错误：无效的讲师编号','back');
			// this.uid = options.uid;
			// this.platform = core.platform;
			// var that = this;
			// this.initData('lector/detail',{uid:this.uid},function(res){
			// 	that.shareinfo = core.initshare(res.lector.name,res.url,res.lector.cover,res.lector.summary);
			// });
			
			let uId = options.id
			console.log(uId)
			  this.jiangshi(uId)
			  this.Count(uId)
			  this.selcourse(uId)
			  this.concern(uId)
			  this.data.specials=[];
			 setTimeout(()=>{
			 	/**
			 	 * 调用课程目录
			 	 */
			 	this.selLike()
			 },100);
		},
		onShareAppMessage(e){
			return {
				title:this.data.lector.name,
				path:core.page(this.shareinfo.url)
			}
		},
		onPullDownRefresh(){
			this.initData('lector/detail',{uid:this.uid},function(res){
				
			});
			uni.stopPullDownRefresh();
		},
		methods:{
			async initData(route, data={}, callback=false){
				var that = this;
				core.get(route,function(res){
					if(typeof(res.message)!='undefined' && typeof(res.type)!='undefined'){
						return core.report(res, true);
					}
					that.data = res;
					uni.setNavigationBarTitle({
						title:res.title
					});
					if(callback){
						callback(res);
					}
				},data);
			},
			async concern(id){
				var that = this
				if((await this.$api.reqGet({
					url:"lecturer/selCount/"+id})).data===null){
					that.data.concern == 0
				}else{
					that.data.concern=(await this.$api.reqGet({
						url:"lecturer/selCount/"+id
					})).data;
				}
			},
			async jiangshi(id){
				var that = this
				/*讲师详情*/
				that.data.lecturer=(await this.$api.reqGet({
					url:"lecturer/selallById/"+id,
				})).data[0];
				console.log(that.data.lecturer)
			},
			async Count(id){
				var that = this
				/*课程总数*/
				that.data.count=(await this.$api.reqGet({
					url:"lecturer/selCountCre/"+id,
				})).data;
			},
			async selcourse(id){
				console.log(id)
				if(id==='undefined'){
					console.log("空空如也")
				}
				var that = this
				/*课程数据*/
				if(((await this.$api.reqGet({url:"/lecturer/selcourse/"+id})).data)===null){
					console.log("空空如也")
				}else{
					that.data.lessons = ((await this.$api.reqGet({url:"/lecturer/selcourse/"+id})).data)
					console.log(that.data.lessons)
				}
			},
			naviTo(page,data={}){
				return core.navito(page,data);
			},
			doback(){
				return core.back();
			},
			/*查询关注讲师表*/
			async selLike(){
				var that = this;
				if(core.userinfo.uid!=0){
					var sel = (await this.$api.reqGet({
						url:"lecturer/selLike/"+core.userinfo.uid,
					})).data;
					console.log(sel)
					console.log(that.data.lecturer)
					if(sel!=null){
						for(var i = 0;i<sel.length;i++){
								if(that.data.lecturer.id===sel[i].lecturerId){
									that.data.lecturer.hasfavor = !(that.data.lecturer.hasfavor)
								}
							}
					}
				}
			},
			/*关注讲师*/
			async doFavor(id){
				if(!this.hasLogin) return core.navito('auth/index',{act:'login'});
				var that = this
				that.data.lecturer.hasfavor = !(that.data.lecturer.hasfavor)
				var a = (await this.$api.reqPost({
					url:"/lecturer/ins",
					data:{
					uid:core.userinfo.uid,
					lecturerId:id,
					}
				})).data;
			},
			async dianzan(){
				var that = this
				console.log(core.userinfo.uid)
				var a = (await this.$api.reqPost({
					url:"/lecturer/ins",
					data:{uid:core.userinfo.uid,
					lecturer:that.data.lecturer.id
					}
				})).data;
				console.log(a)
				// this.$api.reqPost({url:"/lecturer/ins/"+uid,id}).data,
				
				// var a= (await this.$api.reqPost({
				// 	url:"menu/addLike",
				// 	data:{uid:core.userinfo.uid,
				// 		courseId:id,
				// 		classroomCourse:that.data.list[index]},
				// })).data;
			},
			async tableSelect(e){
				that.data.lecturer = (await this.$api.reqGet({url:"/lecturer/selcourse/"+tid})).data;
			}
		}
	}
</script>

<style>
	page{background: #FFFFFF;}
	.lector-detail{position: relative; overflow: hidden;}
	.lector-top .lector-bg{-webkit-filter: blur(5px); -moz-filter: blur(5px); -o-filter: blur(5px); -ms-filter: blur(5px); filter: blur(5px); background-size: cover; background-position: center; background-repeat: no-repeat; position: absolute; left: 0; top: 0; height: 100%; width: 100%;}
	.lector-top .lector-bg::after{position: absolute; width: 100%; height: 100%; background: rgba(0,0,0,0.3); left: 0; top: 0; content: '';}
	.lector-top .user-card .cu-item{background: none !important;}
	.lector-top .user-card .cu-item .content{color: #FFFFFF;}
	.lector-top .user-card .cu-item .text-content{max-height: unset;}
	.lector-total{color: #B7B8BD;}
	.lector-total .text-xl{margin-bottom: 15upx;}
	.lector-content{background: #F2F2F2; padding-top: 12upx;}
	.lector-bio rich-text{line-height: 46upx; font-size: 28upx; color: #666; letter-spacing: 2upx;}
</style>
